package com.wty.cmims.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wty.cmims.pojo.Code;
import com.wty.cmims.pojo.Doctor;
import com.wty.cmims.pojo.ResponseResult;
import com.wty.cmims.service.DoctorService;
import com.wty.cmims.mapper.DoctorMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.Map;

/**
* @author wty
* @description 针对表【doctor】的数据库操作Service实现
* @createDate 2024-11-04 21:23:30
*/
@Service
public class DoctorServiceImpl extends ServiceImpl<DoctorMapper, Doctor>
    implements DoctorService{
    @Autowired
    private DoctorMapper doctorMapper;

    @Override
    @Transactional
    public ResponseResult<Map<String, Object>> doctorsFind(Map<String, Object> paramsMap) {
        ResponseResult<Map<String, Object>> responseResult = new ResponseResult<>();
        Integer pageSize = (Integer) paramsMap.get("pageSize");
        paramsMap.put("start", ((Integer) paramsMap.get("currentPage") - 1) * pageSize);
        responseResult.setPageSize(pageSize);
        List<Map<String, Object>> doctors = doctorMapper.findDoctors(paramsMap);
        Integer total = doctorMapper.findDoctorsNum(paramsMap);
        if (doctors != null) {
            responseResult.setCode(Code.SUCCESS);
            responseResult.setMessage("医生账号查询成功");
            responseResult.setDatas(doctors);
            responseResult.setTotal(total);
            responseResult.setCurrentPage((Integer) paramsMap.get("currentPage"));
        } else {
            responseResult.setCode(Code.ERROR);
            responseResult.setMessage("医生账号查询失败");
        }
        return responseResult;
    }

    @Override
    public ResponseResult<Map<String, Object>> doctorUpdate(Map<String, Object> paramsMap) {
        ResponseResult<Map<String,Object>> responseResult = new ResponseResult<>();
        Integer rows = doctorMapper.updateDoctor(paramsMap);
        if (rows == 2) {
            responseResult.setCode(Code.SUCCESS);
            responseResult.setMessage("医生信息更新成功");
            responseResult.setData(paramsMap);
        } else {
            responseResult.setCode(Code.ERROR);
            responseResult.setMessage("医生信息更新失败");
        }
        return responseResult;
    }
}




